const bodyParser = require('body-parser');
const Mock = require('mockjs');

const data = Mock.mock({
    'list|11-35': [{
        img: '@image(100x100,@color)',
        title: '@ctitle',
        id: '@id'
    }],
    'house|10': [{
        img: '@image(100x100,@color)',
        title: '@ctitle',
        'price|10000-100000': 0,
        'type|1': ['在售', '预售', '尾盘'],
        text: '@ctitle',
        id: '@id'
    }]
})
console.log(data);
module.exports = {
    devServer: {
        before(app) {
            app.use(bodyParser.json())
            app.post('/list', (req, res) => {
                if (req.body.username == 'lxf' && req.body.password == '990616') {
                    res.send({
                        code: 1,
                        mag: '登录成功'
                    })
                } else {
                    res.send({
                        code: 0,
                        mag: '登录失败'
                    })
                }
            })
            app.get('/navList', (req, res) => {
                res.send(data.list)
            })
            app.get('/house', (req, res) => {
                res.send(data.house)
            })
            app.get('/houseDetail',(req,res)=>{
                const {id}=req.query
                const newArr=data.house.filter(item=>{
                    return item.id==id
                })
                res.send(newArr[0])
            })
        }
    }
}